// pages/classify/classify.js
const app = getApp();
import http from "../../utils/http";
import util from "../../utils/util";
Page({
	data: {
		tabs: [], // 标签栏数据
		selectedTab: 0, // 当前选中的标签索引
		showCalendar: false, // 控制日历弹出层显示
		minDate: new Date().getTime(), // 当前日期
		maxDate: new Date().setDate(new Date().getDate() + 7), // 一周以内
		currentDate: null,
		timeSlots: [
			{ time: "14:15", isFull: false },
			{ time: "14:30", isFull: true },
			{ time: "14:45", isFull: false },
			{ time: "15:00", isFull: false },
			{ time: "15:15", isFull: true },
			{ time: "15:30", isFull: false },
			{ time: "15:45", isFull: false },
			{ time: "16:00", isFull: false },
			{ time: "16:15", isFull: true },
			{ time: "16:30", isFull: false },
		],
		selectedTime: "", // 当前选中的时间
	},

	onLoad() {
		this.updateTabs(new Date());
	},
	// 点击时间段
	onTimeSelect(event) {
		const { time, full } = event.currentTarget.dataset;
		this.setData({ selectedTime: time });
	},

	// 更新标签栏数据
	updateTabs(startDate) {
		const tabs = [];
		for (let i = 0; i < 4; i++) {
			const date = new Date(startDate);
			date.setDate(startDate.getDate() + i);
			tabs.push({
				label: `${
					i === 0
						? "今天"
						: i === 1
						? "明天"
						: i === 2
						? "后天"
						: "周" + ["日", "一", "二", "三", "四", "五", "六"][date.getDay()]
				}${date.getMonth() + 1}月${date.getDate()}日`,
				value: date.getTime(),
			});
		}
		console.log(tabs, "tabs");

		this.setData({ tabs });
	},

	// 点击标签
	onTabClick(event) {
		const { index } = event.detail;
		this.setData({ selectedTab: index });
	},

	// 打开日历
	onOpenCalendar() {
		const selectedDate = this.data.tabs[this.data.selectedTab].value; // 获取当前选中标签的日期
		this.setData({
			showCalendar: true,
			currentDate: selectedDate, // 设置日历的当前选中日期为标签的选中项
		});
	},

	// 关闭日历
	onCloseCalendar() {
		this.setData({ showCalendar: false });
	},

	// 确认选择日期
	onDateConfirm(event) {
		this.updateTabs(event.detail);
		this.setData({ selectedTab: 0, showCalendar: false });
		console.log(this.data.selectedTab);
	},
});
